import 'package:flutter/material.dart';

class MyApp2 extends StatelessWidget {
  MyApp2({super.key, this.age});

  int? age;
  final String name = '张三';

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      // 导航条
      appBar: AppBar(
        title: const Text('无状态组件',
            style: TextStyle(color: Colors.white, fontSize: 20)),
        backgroundColor: Colors.pink,
        centerTitle: true,
      ),
      // 主体区域
      body: Center(
        child: Text(
          '我叫$name, 今年$age岁',
          style: const TextStyle(fontSize: 25),
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          age = age! + 1;
          print(age);
        },
        child: const Icon(Icons.add),
      ),
    );
  }
}
